home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 January / Disc 3 / Amethyst.iso / live / usr / lib / PHI / phi-upgrade-end.fixup < prev    next >
Encoding:
Text File  |  2002-07-26  |  3.2 KB  |  130 lines

  1. #!/bin/bash
  2.  
  3. # Fixup /etc/sysconfig/daemons/
  4.  
  5. copyopts='ONBOOT OPTIONS FS_LIST OPTIONS_SMB OPTIONS_NMB NFSD_OPTIONS MOUNTD_OPTIONS OPTIONS_S OPTIONS_D OPTIONS_SYSLOGD OPTIONS_KLOGD INTERNAL_INTERFACE INTERNAL_NETWORK LEVEL CONFIGURED DAEMON_ARGS'
  6.  
  7. for i in /etc/sysconfig/daemons/*.rpmnew 
  8. do
  9.     echo "converting .rpmnew to .rpmsave $i"
  10.     if [ "$i" != "/etc/sysconfig/daemons/*.rpmnew" ] ; then
  11.         daemonf=`echo $i | sed -e 's/.rpmnew//'`
  12.         echo mv $daemonf $daemonf.rpmsave
  13.         mv $daemonf $daemonf.rpmsave
  14.         echo mv $i $daemonf
  15.         mv $i $daemonf
  16.     fi
  17. done
  18.  
  19. for i in /etc/sysconfig/daemons/*.rpmsave 
  20. do
  21.     echo "processing $i"
  22.     if [ "$i" != "/etc/sysconfig/daemons/*.rpmsave" ] ; then
  23.         daemonf=`echo $i | sed -e 's/.rpmsave//'`
  24.         for opt in $copyopts ; do
  25.             opts=`get_val -f $i $opt`
  26.             oldopts=`get_val -f $daemonf $opt`
  27.             # Only migrate values which are not empty.
  28.             # (might be discussable) 
  29.             if [ -n "$opts" ]; then
  30.                 echo "$daemonf setting $opt to $opts"
  31.                 set_val -f $daemonf -- $opt "$opts"
  32.             fi
  33.         done
  34.  
  35.     fi
  36. done
  37.  
  38. # Fixup mounts
  39. if ! grep usbdevfs /etc/fstab > /dev/null ; then
  40.     echo "none /proc/bus/usb usbdevfs defaults 0 0" >> /etc/fstab
  41. fi
  42. if ! grep devpts /etc/fstab > /dev/null ; then
  43.     echo "none /dev/pts devpts gid=5,mode=620 0 0" >> /etc/fstab
  44.     mkdir /dev/pts
  45. fi
  46.  
  47. if ! grep /dev/cdrom /etc/fstab > /dev/null ; then
  48.     echo "/dev/cdrom /mnt/cdrom iso9660 ro,user,noauto,exec 0 0" >> /etc/fstab
  49.     mkdir /mnt/cdrom
  50. fi
  51.  
  52. # Fix users and groups.
  53. # Ugly inline PERL, since we just copy this script into the updated system
  54.  
  55. perl -e << EoF '
  56. # return if something is not as used.
  57. exit 0 if (! -f "/etc/passwd");
  58. exit 0 if (! -f "/etc/passwd~");
  59. exit 0 if (! -f "/etc/group");
  60. exit 0 if (! -f "/etc/group~");
  61.  
  62. open(DIFF,"diff -u /etc/group /etc/group~|");
  63. $junk=<DIFF>; $junk=<DIFF>; $junk=<DIFF>;
  64. %needadd=();
  65. while (<DIFF>) {
  66.     chomp;
  67.     if (/^\+/) {
  68.         s/^\+//;
  69.         @foo=split(/:/);
  70.         next if ($#foo<2);
  71.         $needadd{$foo[0]}=$_;
  72.         next;
  73.     }
  74.     if (/^\-/) {
  75.         s/^\-//;
  76.         @foo=split(/:/);
  77.         next if ($#foo<2);
  78.         $needadd{$foo[0]} = 0;
  79.         next;
  80.     }
  81. }
  82.  
  83. foreach (keys %needadd) {
  84.     next if (!$needadd{$_});
  85.     @foo = split(/:/,$needadd{$_});
  86.     print STDERR "/usr/sbin/groupadd -g $foo[2] $foo[0]\n";
  87.     system("/usr/sbin/groupadd -g $foo[2] $foo[0]") && warn "system groupadd failed.\n";
  88. }
  89. close(DIFF);
  90.  
  91. open(DIFF,"diff -u /etc/passwd /etc/passwd~|");
  92. $junk=<DIFF>; $junk=<DIFF>; $junk=<DIFF>;
  93. %needadd=();
  94. while (<DIFF>) {
  95.     chomp;
  96.     if (/^\+/) {
  97.         s/^\+//;
  98.         @foo=split(/:/);
  99.         next if ($#foo<6);
  100.         $needadd{$foo[0]}=$_;
  101.         next;
  102.     }
  103.     if (/^\-/) {
  104.         s/^\-//;
  105.         @foo=split(/:/);
  106.         next if ($#foo<6);
  107.         $needadd{$foo[0]} = 0;
  108.         next;
  109.     }
  110. }
  111. close(DIFF);
  112.  
  113. foreach (keys %needadd) {
  114.     next if (!$needadd{$_});
  115.     @foo = split(/:/,$needadd{$_});
  116.     print STDERR "/usr/sbin/useradd -p $foo[1] -u $foo[2] -g $foo[3] -c $foo[4] -d $foo[5] -s $foo[6] $foo[0]\n";
  117.     system("/usr/sbin/useradd -p $foo[1] -u $foo[2] -g $foo[3] -c \"$foo[4]\" -d $foo[5] -s $foo[6] $foo[0]") && warn "system useradd failed.\n";
  118. }
  119.  
  120. # FIXME FIXME FIXME: does not handle /etc/shadow. But those system accounts
  121. # usually do not add passwords there anyway.
  122. EoF
  123. '
  124.  
  125. # fixup probably missing init.d symlinks (due to broken PHI magic)
  126. for i in network netmount slpd firewall portmap
  127. do
  128.     /usr/lib/LSB/init-install $i
  129. done
  130.